<!--
 子流程
-->
<template>
  <a-spin class="main" :spinning="spinning">
    <a-modal
      :open="modalVisible"
      :centered="true"
      :title="modalTitle"
      :mask-closable="false"
      wrap-class-name="main_modal"
      :width="800"
      :body-style="bodyStyle"
      :destroy-on-close="true"
      :style="modalStyle"
      @afterClose="afterClose"
      @cancel="closeModal"
    >
      <div class="main-box" style="height: 100%">
        <div v-if="userBoxList.length > 0">
          <a-tabs
            v-model="selectFlowTab"
            :class="userBoxList.length == 1 ? ' user-tab head-tab-single' : 'head-tab'"
            default-active-key="0"
            @change="changeTabs"
          >
            <a-tab-pane v-for="(item, index) in userBoxList" :key="index">
              <template v-slot:tab>
                <span class="head-tab">
                  <span v-if="userBoxList.length == 1">
                    <!-- 如果点击的是自定义选人按钮则标题为自定义选人 -->
                    <span v-if="submitFuncName === 'BpmStepuserdefinedSubmit'">配置选人</span>
                    <span v-else>
                      请{{ titleAction }}{{ bpmInstanceObject.bpmCommonSelect.isShowOpinionNode === false ? '' : title }}{{ actionObject }}
                    </span>
                  </span>
                  <span v-if="isMustUser(index) && !needSelectUser" class="required">*</span>
                  <a-tooltip v-if="userBoxList.length > 1">
                    <template v-slot:title>
                      {{ item.name }}
                    </template>
                    {{ item.name }}
                  </a-tooltip>
                </span>
              </template>
              <div class="choose">
                <div ref="subcontent" class="subcontent left">
                  <a-tabs v-model:activeKey="selectTag" type="card" destroy-inactive-tab-pane @change="changeHeadTag">
                    <a-tab-pane v-for="tab in item.tabs" :key="tab.nodeType" :tab="tab.name" />
                  </a-tabs>
                  <template v-for="(tab, tabIndex) in item.tabs" :key="tab.nodeType">
                    <div v-show="tab.nodeType === selectTag" class="tree-box">
                      <select-tree
                        v-if="tab.nodeType == 'orgDept' || viewType == 'tree'"
                        :key="tab.nodeType"
                        :ref="treeRefName + index + tab.nodeType"
                        :type="tab.nodeType"
                        :button-data="buttonData"
                        :visible="visible"
                        :select="{ selectTag: selectTag, selectFlowTab: selectFlowTab }"
                        :data="taskUserSelect"
                        :default-selected-user="selectUser"
                        :bpm-instance-object="bpmInstanceObject"
                        :show-more-user-info="showMoreUserInfo"
                        :check-children-node="checkChildrenNode"
                        @loading="onTreeLoading"
                        @changeSelectUser="onChange"
                      />
                      <select-table
                        v-if="tab.nodeType != 'orgDept' && viewType == 'table'"
                        :key="tabIndex"
                        :ref="treeRefName + index + tab.nodeType"
                        :type="tab.nodeType"
                        :button-data="buttonData"
                        :visible="visible"
                        :select="{ selectTag: selectTag, selectFlowTab: selectFlowTab }"
                        :data="taskUserSelect"
                        :default-selected-user="selectUser"
                        :bpm-instance-object="bpmInstanceObject"
                        :show-more-user-info="showMoreUserInfo"
                        :check-children-node="checkChildrenNode"
                        @loading="onTreeLoading"
                        @changeSelectUser="onChange"
                      />
                    </div>
                  </template>
                </div>
                <div ref="pullRefresh" class="right">
                  <div ref="inputBox" class="input-box">
                    <select-user-box
                      :ref="selectUserBoxRefName + index"
                      :select-flow-tab="selectFlowTab"
                      :user-box-list="userBoxList"
                      :show-more-user-info="showMoreUserInfo"
                      @changeSelectUser="changeSelectUser"
                    />
                  </div>
                </div>
              </div>
            </a-tab-pane>
            <!--<span
              class="main-tab-bar"
              style="width: 48px; height: 48px; display: inline-block"
              slot="tabBarExtraContent"
            />-->
          </a-tabs>
        </div>
        <bpm-opinion
          v-if="isShowFlowOpinion"
          :ref="flowOpinionRefName"
          :visible="visible"
          :button-data="buttonData"
          :user-select-visible="userBoxList.length > 0 ? true : false"
          :textarea-max="flowOpinionLength"
          :bpm-instance-object="bpmInstanceObject"
          v-bind="$attrs"
        />
      </div>
      <template v-slot:footer>
        <a-button
          v-for="(button, index) in buttonsList"
          :key="index"
          :type="button.key != 'cancel' ? 'primary' : 'default'"
          :loading="spinningButton && button.key == 'confirm'"
          @click="() => clickModal(button.key)"
        >
          {{ button.name }}
        </a-button>
      </template>
    </a-modal>
    <select-work-hand-user
      ref="selectWorkHandUser"
      :process-key="processKey"
      :user-list="selectWorkHand"
      :bpm-instance-object="bpmInstanceObject"
      @closeSelectWorkHandUserList="closeSelectWorkHandUserList"
      @getSelectWorkHandUserList="getSelectWorkHandUserList"
    />
  </a-spin>
</template>
<!-- eslint-disable max-lines -->
<script>
import SelectTree from './SelectTree.vue';
import SelectTable from './SelectTable.vue';

import SelectUserBox from './SelectUserBox.vue';
import SelectWorkHandUser from '../bpm-buttons-modal/SelectWorkHandUser.vue';
import BpmOpinion from './BpmOpinion.vue';
import bpmUtils from '../../../bpmutils/FlowUtils';
import { isAutoSelectUser, setUserList } from './_util';
import request from '@/utils/request';

const tabs = {
  org: { id: 1, name: '部门', nodeType: 'orgDept', para: [] },
  user: { id: 2, name: '用户', nodeType: 'user', para: [] },
  group: { id: 3, name: '群组', nodeType: 'group', para: [] },
  role: { id: 4, name: '角色', nodeType: 'role', para: [] },
  position: { id: 5, name: '岗位', nodeType: 'position', para: [] },
  otg: { id: 5, name: '关系', nodeType: '', para: [] }
};
const buttons = {
  confirm: { name: '确定', key: 'confirm' },
  cancel: { name: '取消', key: 'cancel' },
  agree: { name: '同意并提交', key: 'agreeAndSubmit' },
  disagree: { name: '不同意并提交', key: 'disagreeAndSubmit' }
};
export default {
  name: 'AvicBpmCommonSelect',
  components: {
    BpmOpinion,
    SelectTree,
    SelectTable,
    SelectUserBox,
    SelectWorkHandUser
  },
  props: {
    buttonData: {
      required: false,
      type: Object,
      default: null
    },
    visible: {
      type: Boolean,
      required: false,
      default: false
    },
    // 是否显示编辑框
    isShowOpinion: {
      type: Boolean,
      required: false,
      default: true
    },
    // 默认选中人员
    defaultSelectUsers: {
      required: false,
      type: Object,
      default: null
    },
    // 流程实例
    bpmInstanceObject: {
      type: Object,
      default: null
    },
    // check时选中孙子节点,打开时会层层异步加载子节点的子节点，关闭时只加载一层子节点
    checkChildrenNode: {
      type: Boolean,
      required: false,
      default: window.$config?.flow?.bpmCommonSelect?.checkChildrenNode ?? true
    },
    // 用户、角色、岗位、群组展示的视图类型 tree:树形结构 table:表格结构
    viewType: { type: String, default: window.$config?.flow?.bpmCommonSelect?.viewType ?? 'tree' }
  },
  data() {
    return {
      modalStyle: {
        opacity: 1
      },
      bodyStyle: { padding: '0px', overflowY: 'hidden' },
      modalTitle: null,
      selectVisible: false, // 窗口是否显示
      refersTop: `${78.5}px`, // 尖头高度
      selectFlowTab: 0, // 选择的切换页
      selectUser: [], // 选择的用户
      selectTag: '', // 树上方选中的按钮
      treeRefName: 'selectTree',
      isTreeLoading: false,
      selectUserBoxRefName: 'selectUserBox',
      flowOpinionRefName: 'flowOpinion',
      getActJsonInfoParam: {
        // 弹窗详情的请求接口
        url: `${bpmUtils.baseurl}/business/getActJsonInfo2/v1`,
        method: 'post'
      },
      // 获取配置选人用户
      bpmStepPersonParam: {
        url: `${bpmUtils.baseurl}/business/getBpmStepPerson/v1`,
        method: 'post'
      },
      taskUserSelect: [],
      // 按钮集合
      buttonsList: [],
      // 选择框集合
      userBoxList: [],
      submitFuncName: '', // 提交按钮名称
      title: '', // 标题名称
      titleAction: '选择', // 标题动作
      actionObject: '处理人',
      spinning: false, // 加载状态
      spinningButton: false, // 按钮状态
      formId: '',
      selectWorkHand: [], // 流程委托
      processKey: '', // 流程委托
      needSelectUser: false, // 判断是否选人
      compelManner: '', // 选人表态
      isNotShowModal: 0, // 是否显示意见
      isShowFlowOpinion: true, // 是否显示意见
      // flowOpinionHeight: 60, // 意见框高度控制
      flowOpinionLength: 500, // 流程意见长度
      showMoreUserInfo: ['deptNamePath'], // 流程选人显示全路径
      modalVisible: false
    };
  },
  /* //注册接受组件传参事件
  computed: {
    ...mapGetters(['getSelectVisible'])
  }, */
  // 接收组件传参
  watch: {
    'bpmInstanceObject.bpmCommonSelect.selectVisible': {
      immediate: true,
      handler(selectVisible) {
        this.selectVisible = selectVisible;
        // 关闭弹窗
        if (this.modalVisible && !selectVisible) {
          this.modalVisible = this.selectVisible;
        }
        if (selectVisible) {
          this.selectFlowTab = 0;
          this.getActJsonInfo();
        } else {
          this.empty();
        }
      }
    },
    visible: {
      immediate: true,
      handler(newV) {
        this.selectVisible = newV;
        if (newV) {
          this.selectFlowTab = 0;
          this.getActJsonInfo();
        } else {
          this.empty();
        }
      }
    },
    isShowOpinion: {
      immediate: true,
      handler(newV) {
        this.isShowFlowOpinion = newV;
      }
    }
  },
  created() {
    this.init();
  },
  activated() {
    if (this.$refs.pullRefresh) {
      this.$refs.pullRefresh.scrollTop = this.scroll;
    }
  },
  methods: {
    BpmSubmitSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmSubmit.BpmSubmitSubmit(bpmInstanceObject, params);
    },
    executeTodraftSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmRetreat.executeTodraftSubmit(bpmInstanceObject, params);
    },
    executeToprevSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmRetreat.executeToprevSubmit(bpmInstanceObject, params);
    },
    executeTowantSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmRetreat.executeTowantSubmit(bpmInstanceObject, params);
    },
    BpmWithdrawSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmWithdraw.BpmWithdrawSubmit(bpmInstanceObject, params);
    },
    BpmSupplementSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmSupplement.BpmSupplementSubmit(bpmInstanceObject, params);
    },
    BpmTransmitSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmTransmit.BpmTransmitSubmit(bpmInstanceObject, params);
    },
    BpmAdduserSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmAdduser.BpmAdduserSubmit(bpmInstanceObject, params);
    },
    BpmWithdrawassigneeSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmWithdrawassignee.BpmWithdrawassigneeSubmit(bpmInstanceObject, params);
    },
    BpmSupersedeSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmSupersede.BpmSupersedeSubmit(bpmInstanceObject, params);
    },
    BpmStepuserdefinedSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmStepuserdefined.BpmStepuserdefinedSubmit(bpmInstanceObject, params);
    },
    BpmTaskreaderSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmTaskreader.BpmTaskreaderSubmit(bpmInstanceObject, params);
    },
    BpmStartsubflowSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmStartsubflow.BpmStartsubflowSubmit(bpmInstanceObject, params);
    },
    BpmGlobaljumpSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmGlobaljump.BpmGlobaljumpSubmit(bpmInstanceObject, params);
    },
    BpmGlobalendSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmGlobalend.BpmGlobalendSubmit(bpmInstanceObject, params);
    },
    executeToactivitySubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmRetreat.executeToactivitySubmit(bpmInstanceObject, params);
    },
    openSelectWorkHandUserModal(bpmInstanceObject) {
      return this.bpmInstanceObject.bpmSelectWorkHandUser.openSelectWorkHandUserModal(bpmInstanceObject);
    },
    BpmAdduserAndSubmitSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmAdduserAndSubmit.BpmAdduserAndSubmitSubmit(bpmInstanceObject, params);
    },
    BpmWithdrawPartSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmWithdrawPart.BpmWithdrawPartSubmit(bpmInstanceObject, params);
    },
    transmitSubmit(bpmInstanceObject, params) {
      return this.bpmInstanceObject.bpmTransmitSubmit.transmitSubmit(bpmInstanceObject, params);
    },
    // ...mapActions([
    //   'closeBpmCommonSelect',
    //   'BpmSubmitSubmit',
    //   'executeTodraftSubmit',
    //   'executeToprevSubmit',
    //   'executeTowantSubmit',
    //   'BpmWithdrawSubmit',
    //   'BpmSupplementSubmit',
    //   'BpmTransmitSubmit',
    //   'BpmAdduserSubmit',
    //   'BpmWithdrawassigneeSubmit',
    //   'BpmSupersedeSubmit',
    //   'BpmStepuserdefinedSubmit',
    //   'BpmTaskreaderSubmit',
    //   'BpmStartsubflowSubmit',
    //   'BpmGlobaljumpSubmit',
    //   'BpmGlobalendSubmit',
    //   'executeToactivitySubmit',
    //   'openSelectWorkHandUserModal'
    // ]),
    // 初始化函数
    init() {
      //
    },
    onTreeLoading(isTreeLoading) {
      this.isTreeLoading = isTreeLoading;
    },
    changeHeadTag(nodeType) {
      /* 当前维度的数据加载中时，不可切换到其他维度 */
      if (this.isTreeLoading) {
        return;
      }
      this.selectTag = nodeType;
      setTimeout(() => {
        const selectUserBoxRef = this.selectUserBoxRefName + this.selectFlowTab;
        if (this.$refs[selectUserBoxRef] && this.$refs[selectUserBoxRef].length >= 0) {
          this.$refs[selectUserBoxRef][0].getUserData(this.selectUser);
        }
        this.changeSelectUser(this.selectUser);
      }, 500);
    },
    // 判断是否显示选人框
    showSelectUser(taskUserSelect) {
      const bpmCommonSelect = this.getButtonData();
      const { event } = bpmCommonSelect.buttonData;
      if (!taskUserSelect.nextTask) {
        return false;
      }
      // #46383 如果点击的是配置选人按钮，则必须弹出选人框
      if (event === 'dostepuserdefined') {
        return true;
      }
      if (isAutoSelectUser(event)) {
        return false;
      }
      let endTypeNum = 0;
      for (let i = 0; i < taskUserSelect.nextTask.length; i++) {
        const nextActorModel = taskUserSelect.nextTask[i];
        if (nextActorModel.activityType === 'sub-process' || nextActorModel.activityType === 'foreach') {
          if (nextActorModel.currentActivityAttr.isMustUser === 'yes') {
            return true;
          }
        } else if (nextActorModel.activityType === 'end') {
          endTypeNum = endTypeNum + 1;
          // return false;
        } else {
          if (nextActorModel.currentActivityAttr.isSelectUser === 'yes') {
            return true;
          }
        }
      }
      if (endTypeNum === taskUserSelect.nextTask.length) {
        return false;
      }

      return false;
    },
    // 强制表态
    isIdeaCompelManner(taskUserSelect) {
      if (taskUserSelect.currentActivityAttr.ideaCompelManner) {
        if (taskUserSelect.currentActivityAttr.ideaCompelManner === 'yes') {
          // 强制
          return true;
        }
        return false; // 不强制
      }
      return false; // 不强制
    },
    // 初始化加载选人组件
    getActJsonInfo() {
      const bpmCommonSelect = this.getButtonData();
      if (this.validationOpenSelect(bpmCommonSelect)) {
        this.spinning = true;
        // 初始化按钮
        if (bpmCommonSelect.buttonData) {
          this.submitFuncName = bpmCommonSelect.submitFuncName;

          // if (bpmCommonSelect.buttonData.alias) {
          //   this.title = '【' + bpmCommonSelect.buttonData.alias + '】';
          // } else if (bpmCommonSelect.buttonData.lable) {
          //   this.title = '【' + bpmCommonSelect.buttonData.lable + '】';
          // }
          this.buttonsList = [];
          this.buttonsList.push(buttons.cancel);
          this.buttonsList.push(buttons.confirm);
          const parameter = {
            procinstDbid: bpmCommonSelect.buttonData.procinstDbid,
            executionId: bpmCommonSelect.buttonData.executionId,
            taskId: bpmCommonSelect.buttonData.taskId,
            outcome: bpmCommonSelect.buttonData.name,
            targetActivityName: bpmCommonSelect.buttonData.targetActivityName,
            type: bpmCommonSelect.buttonData.event
          };
          request({
            url: this.getActJsonInfoParam.url,
            data: parameter,
            method: this.getActJsonInfoParam.method
          }) // 提交
            .then((res) => {
              if (res.success) {
                this.formId = res.data.formId;
                this.initUserSelectBox(res.data);
              } else {
                this.$message.error('打开选人失败，缺少参数');
                this.closeModal();
              }
              this.spinning = false;
            })
            .catch((error) => {
              this.spinning = false;
              if (error?.message?.indexOf('timeout of') !== -1) {
                this.$message.error('打开选人失败，请联系管理员查看配置是否正确！');
              } else {
                this.$message.error('打开选人失败，系统错误');
              }
              this.closeModal();
            });
        } else {
          this.spinning = false;
          this.$message.error('打开选人失败，缺少参数');
          this.closeModal();
        }
      } else {
        this.$message.error('打开选人失败，缺少参数');
        this.closeModal();
      }
    },
    // 验证打开选人参数是否完整
    validationOpenSelect(bpmCommonSelect) {
      let result = false;
      if (bpmCommonSelect && bpmCommonSelect.buttonData) {
        if (bpmCommonSelect.buttonData) {
          if (bpmCommonSelect.buttonData.procinstDbid && bpmCommonSelect.buttonData.executionId) {
            result = true;
          }
        }
      }
      return result;
    },
    // 初始化选人区域
    initUserSelectBox(actInfo) {
      this.userBoxList = [];
      let nextTask = [];
      let taskUserSelect = {};
      if (actInfo) {
        if (actInfo.taskUserSelect) {
          taskUserSelect = actInfo.taskUserSelect;
        } else {
          taskUserSelect = actInfo;
        }
      }
      this.taskUserSelect = taskUserSelect;
      this.needSelectUser = this.noNeedSelectUser(); // 获取是否选人
      // 强制表态--仅提交类操作
      const bpmCommonSelect = this.getButtonData();
      if (this.isIdeaCompelManner(taskUserSelect) && bpmCommonSelect.buttonData.event === 'dosubmit') {
        this.buttonsList = [];
        this.buttonsList.push(buttons.cancel);
        this.buttonsList.push(buttons.agree);
        this.buttonsList.push(buttons.disagree);
      }
      if (this.showSelectUser(taskUserSelect) && taskUserSelect.nextTask && taskUserSelect.nextTask.length > 0) {
        taskUserSelect.nextTask = taskUserSelect.nextTask.filter((tim) => tim.activityType !== 'end');
        // 解决 #46374 人工节点-基本信息-意见，在勾选了节点权限“抄送”的前提下，允许提交不弹框设置后就不生效了。
        // 勾选了抄送 并且 不用选人，不用强制表态，提交意见配置“可以不填”，并且勾选“允许提交不弹框”，不显示意见框，直接提交
        if (
          !(this.isIdeaCompelManner(taskUserSelect) && bpmCommonSelect.buttonData.event === 'dosubmit') &&
          taskUserSelect.currentActivityAttr.ideaType === 'can' &&
          taskUserSelect.currentActivityAttr.canHideDialog === 'yes'
        ) {
          const hasCarbonCopy = taskUserSelect.nextTask.filter((item) => item.activityType === null);
          const unHasCarbonCopy = taskUserSelect.nextTask.filter((item) => item.activityType === 'task');
          // 抄送存在且下个节点允许不弹框 就只弹出抄送选人框
          if (hasCarbonCopy.length && unHasCarbonCopy.length && unHasCarbonCopy[0].currentActivityAttr.isSelectUser === 'no') {
            nextTask = hasCarbonCopy;
            taskUserSelect.nextTask = nextTask;
          } else {
            nextTask = taskUserSelect.nextTask;
          }
        } else {
          nextTask = taskUserSelect.nextTask;
        }
        nextTask.forEach((tim, index) => {
          const selectFlowTabs = [];
          // 部门
          if (tim.orgList.length > 0 || tim.deptList.length > 0) {
            const { org } = tabs;
            const mapList = tim.orgList.length > 0 ? tim.orgList : tim.deptList;
            mapList.forEach((tim) => {
              org.para.push(tim.id);
            });
            selectFlowTabs.push(org);
          }
          // 用户
          if (tim.userList.length > 0) {
            tim.userList.sort((abc, def) => abc.orderBy - def.orderBy);
            const { user } = tabs;
            tim.userList.forEach((tim) => {
              user.para.push(tim.id);
            });
            selectFlowTabs.push(user);
          }
          // 群组
          if (tim.groupList.length > 0) {
            const { group } = tabs;
            tim.groupList.forEach((tim) => {
              group.para.push(tim.id);
            });
            selectFlowTabs.push(group);
          }
          // 角色
          if (tim.roleList.length > 0) {
            const { role } = tabs;
            tim.roleList.forEach((tim) => {
              role.para.push(tim.id);
            });
            selectFlowTabs.push(role);
          }
          // 岗位
          if (tim.positionList.length > 0) {
            const { position } = tabs;
            tim.positionList.forEach((tim) => {
              position.para.push(tim.id);
            });
            selectFlowTabs.push(position);
          }
          const data = {
            id: index,
            name: taskUserSelect.nextTask.length > 1 ? tim.currentActivityAttr.activityAlias : '',
            tabs: selectFlowTabs
          };
          this.userBoxList.push(data);
          if (index === 0) {
            if (selectFlowTabs.length === 0) {
              this.spinning = false;
              this.$message.error('没有符合要求的处理人！');
            } else {
              this.selectTag = selectFlowTabs[0].nodeType;
            }
          }
          // if (this.selectUser && this.selectUser.length > 0) {
          //   this.selectUser.map((user, i) => {
          //     if (user.selectFlowTab != index) {
          //       this.selectUser.push({
          //         selectFlowTab: index,
          //         users: []
          //       });
          //     }
          //   });
          // } else {
          const select = this.selectUser.filter((us) => us.selectFlowTab === index);
          if (select.length <= 0) {
            this.selectUser.push({
              selectFlowTab: index,
              users: []
            });
          }
          // }
        });
        if (this.titleAction === '输入') {
          this.titleAction = '选择';
          this.actionObject = '处理人';
        }
      } else {
        if (taskUserSelect.nextTask && taskUserSelect.nextTask.length > 0) {
          taskUserSelect.nextTask = taskUserSelect.nextTask.filter((tim) => tim.activityType !== 'end');
          taskUserSelect.nextTask.forEach((tim, index) => {
            // if (this.selectUser && this.selectUser.length > 0) {
            //   this.selectUser.map(user => {
            //     if (user.selectFlowTab != index) {
            //       this.selectUser.push({
            //         selectFlowTab: index,
            //         users: []
            //       });
            //     }
            //   });
            // } else {
            const select = this.selectUser.filter((us) => us.selectFlowTab === index);
            if (select.length <= 0) {
              this.selectUser.push({
                selectFlowTab: index,
                users: []
              });
            }
            // }
          });
        }

        this.titleAction = '输入';
        this.actionObject = '处理意见';
        this.bodyStyle.height = '300px';
        // this.flowOpinionHeight = 190;
      }

      if (nextTask && nextTask.length === 1) {
        if (nextTask[0].currentActivityAttr && nextTask[0].currentActivityAttr.activityAlias) {
          // this.title = '【' + taskUserSelect.nextTask[0].currentActivityAttr?.activityAlias + '】';
          if (!this.showSelectUser(taskUserSelect)) {
            // #31492 不显示选人框时，提交流程页面意见输入框title显示不对，应显示当前节点名称
            this.title = `【${taskUserSelect.currentActivityAttr.activityAlias || this.bpmInstanceObject.bpmModel.activitylabel}】`;
          } else {
            this.title = `【${nextTask[0].currentActivityAttr?.activityAlias}】`;
          }
        } else {
          this.title = '';
        }
      } else {
        this.title = '';
      }
      if (this.userBoxList.length === 0) {
        // 弹出的意见框，是否显示【节点信息】
        if (this.bpmInstanceObject.bpmCommonSelect.isShowOpinionNode === false) {
          this.modalTitle = `请${this.titleAction}${this.actionObject}`;
        } else {
          this.modalTitle = `请${this.titleAction}${this.title}${this.actionObject}`;
        }
      } else {
        this.modalTitle = null;
      }
      // 设置默认选人
      if (this.bpmInstanceObject.bpmCommonSelect.defaultSelectUsers != null) {
        this.setDefaultSelectUsers(this.bpmInstanceObject.bpmCommonSelect.defaultSelectUsers);
      }
      // 是否显示流程意见框
      if (typeof this.bpmInstanceObject.bpmCommonSelect.isShowOpinion != 'undefined') {
        this.isShowFlowOpinion = this.bpmInstanceObject.bpmCommonSelect.isShowOpinion;

        if (this.userBoxList.length > 0) {
          this.bodyStyle.height = '520px';
          this.modalStyle.opacity = 1;
        } else {
          // 不用选人，不用强制表态，提交意见配置“可以不填”，并且勾选“允许提交不弹框”，不显示意见框，直接提交
          if (
            !(this.isIdeaCompelManner(taskUserSelect) && bpmCommonSelect.buttonData.event === 'dosubmit') &&
            taskUserSelect.currentActivityAttr.ideaType === 'can' &&
            taskUserSelect.currentActivityAttr.canHideDialog === 'yes'
          ) {
            this.isShowFlowOpinion = false;
            this.isNotShowModal = true;
            this.modalStyle.opacity = 0;
            let confirmTitle = '';
            if (bpmCommonSelect.buttonData.event === 'dowithdraw') {
              confirmTitle = '确定拿回吗？';
            } else {
              confirmTitle = '确定提交吗？';
            }
            this.$confirm({
              title: confirmTitle,
              okText: '确定',
              cancelText: '取消',
              onOk: () => {
                this.clickModal('confirm');
              },
              onCancel: () => {
                this.closeModal();
              }
            });
          }
        }
      }
      // 如果是自定义选人则不显示输入意见框
      if (this.submitFuncName === 'BpmStepuserdefinedSubmit') {
        this.isShowFlowOpinion = false;
      }
      // 最后再设置高度
      // if (this.isShowFlowOpinion === false) {
      //   this.bodyStyle.height = '400px';
      // } else {
      //   this.flowOpinionHeight = 80;
      //   this.bodyStyle.height = '520px';
      // }

      if (this.isNotShowModal) {
        this.modalVisible = false;
      } else {
        this.modalVisible = this.selectVisible;
      }

      if (this.defaultSelectUsers != null) {
        this.setDefaultSelectUsers(this.defaultSelectUsers);
      }
      // 去掉重复的选择用户
      this.repeatSelectUser();
      // 自动选人
      this.autoSelectToCheckUserList();
      // 仅配置选人按钮需要读取配置选择
      if (bpmCommonSelect.buttonData.event === 'dostepuserdefined') {
        this.getBpmStepPerson();
      }

      setTimeout(() => {
        this.setValueToTreeAndBox();
      }, 600);
    },
    // 切换tabs页签
    changeTabs(e) {
      if (typeof e == 'object') {
        if (this.selectFlowTab !== e.index) {
          if (this.userBoxList.length >= e.index && this.userBoxList[e.index].tabs.length > 0) {
            this.changeHeadTag(this.userBoxList[e.index].tabs[0].nodeType);
          }
          this.selectFlowTab = e.index;
        }
      } else if (typeof e == 'number') {
        if (this.userBoxList.length >= e && this.userBoxList[e].tabs.length > 0) {
          this.changeHeadTag(this.userBoxList[e].tabs[0].nodeType);
        }
        this.selectFlowTab = e;
        this.selectTag = this.userBoxList[e].tabs[0].nodeType;
      }
    },
    // 点击取消
    closeModal() {
      if (this.visible) {
        this.selectVisible = false;
        this.$emit('closeBpmSelectUser');
        this.empty();
      } else {
        this.bpmInstanceObject.bpmCommonSelect.closeBpmCommonSelect(this.bpmInstanceObject);
        this.selectVisible = false;
      }
      this.modalVisible = this.selectVisible;
    },
    clickModal(type) {
      // 取消
      if (type === 'cancel') {
        this.closeModal();
        // 确定
      } else if (type === 'confirm') {
        let compelManner = '';
        // 强制表态--仅提交类操作
        const bpmCommonSelect = this.getButtonData();
        if (this.isIdeaCompelManner(this.taskUserSelect) && bpmCommonSelect.buttonData.event === 'dosubmit') {
          compelManner = 'yes';
        }
        this.confirm(compelManner);
        // 同意并提交
      } else if (type === 'agreeAndSubmit') {
        this.confirm('yes');
        // 不同意并提交
      } else if (type === 'disagreeAndSubmit') {
        this.confirm('no');
      }
    },
    checkWord(text = '') {
      if (text === '') return 0;
      const curLen = text.replace(/[^\0x00-\xff]/g, '*').length;
      return Math.floor(curLen);
    },
    // 点击确定
    confirm(compelManner) {
      this.compelManner = compelManner;
      const { nextTask } = { ...this.taskUserSelect };
      const updatedNextTask = nextTask ? nextTask.map((item, i) => ({ ...item, usersList: this.selectUser[i].users })) : [];
      // eslint-disable-next-line max-len
      const unHasCarbonCopy = (updatedNextTask || []).filter((item) => item.currentActivityAttr.activityName !== 'carbonCopy');
      if (
        this.$refs[this.flowOpinionRefName] &&
        this.checkWord(this.$refs[this.flowOpinionRefName].getInputText()) > this.flowOpinionLength
      ) {
        this.$message.warning(`流程意见超出长度${this.flowOpinionLength}`);
        return;
      }
      if (!this.needSelectUser && this.submitFuncName !== 'BpmStepuserdefinedSubmit') {
        if (this.selectUser.length < 1) {
          this.$message.error('请选择处理人');
        } else if (this.selectUser.length === 1 && (this.selectUser[0].users == null || this.selectUser[0].users.length === 0)) {
          this.$message.error('请选择处理人');
        } else if (unHasCarbonCopy.length === 1 && unHasCarbonCopy[0].usersList.length === 0) {
          this.$message.error('请选择处理人');
        } else if (this.isSelectUser()) {
          this.$message.error(this.isSelectUser());
        } else if (this.isOpinion() === false) {
          this.$message.error('请填写流程意见');
        } else {
          this.spinningButton = true;
          const result = this.getResultUserData(compelManner);
          const bpmCommonSelect = this.getButtonData();
          // 流程委托
          if (this.checkWorkHandUser()) {
            this.openWorkHandUser(result);
            if (this.modalStyle.opacity === 0) {
              this.modalStyle.opacity === 1;
            }
          } else {
            if (this.visible) {
              this.$emit('bpmSubmit', { users: result, buttonData: bpmCommonSelect.buttonData });
              this.selectVisible = false;
              this.bpmInstanceObject.bpmCommonSelect.closeBpmCommonSelect(this.bpmInstanceObject);
            } else {
              if (this.submitFuncName) {
                this[this.submitFuncName](this.bpmInstanceObject, {
                  users: JSON.stringify(result),
                  buttonData: bpmCommonSelect.buttonData
                });
              } else {
                this.$emit('afterBpmButtons', {
                  users: result,
                  buttonData: bpmCommonSelect.buttonData
                });
                this.$emit('bpmSubmit', { users: result, buttonData: bpmCommonSelect.buttonData });
                this.selectVisible = false;
                this.bpmInstanceObject.bpmCommonSelect.closeBpmCommonSelect(this.bpmInstanceObject);
              }
            }
          }
          setTimeout(() => {
            this.spinningButton = false;
          }, 2000);
        }
      } else {
        if (this.isOpinion() === false) {
          this.$message.error('请填写流程意见');
          return;
        }
        this.spinningButton = true;
        const result = this.getResultUserData(compelManner);
        const bpmCommonSelect = this.getButtonData();
        // 配置选人后刷新流程图以及已配置人员列表
        if (this.submitFuncName === 'BpmStepuserdefinedSubmit') {
          window.bpmNodeSelectFlowChartRefresh();
        }
        // 流程委托
        if (this.checkWorkHandUser()) {
          this.openWorkHandUser(result);
          if (this.modalStyle.opacity === 0) {
            this.modalStyle.opacity === 1;
          }
        } else {
          if (this.visible) {
            this.$emit('bpmSubmit', { users: result, buttonData: bpmCommonSelect.buttonData });
            this.selectVisible = false;
          } else {
            if (this.submitFuncName) {
              this[this.submitFuncName](this.bpmInstanceObject, {
                users: JSON.stringify(result),
                buttonData: bpmCommonSelect.buttonData
              });
            } else {
              this.$emit('afterBpmButtons', {
                users: result,
                buttonData: bpmCommonSelect.buttonData
              });
              this.$emit('bpmSubmit', { users: result, buttonData: bpmCommonSelect.buttonData });
              this.selectVisible = false;
            }
          }
        }
        setTimeout(() => {
          this.spinningButton = false;
        }, 2000);
      }
    },
    /**
     * 分支节点必须选人
     */
    isMustUser(index) {
      if (index > -1) {
        if (this.taskUserSelect.nextTask && this.taskUserSelect.nextTask.length > 1) {
          if (
            this.taskUserSelect.nextTask[index].currentActivityAttr.isMustUser &&
            this.taskUserSelect.nextTask[index].currentActivityAttr.isMustUser === 'no'
          ) {
            // 必须选人
            return false;
          }
          return true; // 必须选人
        }
        return false; // 默认值
      }
      return false;
    },
    // 判断是否选人
    isSelectUser() {
      let resMessage = '';
      if (this.taskUserSelect && this.taskUserSelect.nextTask && this.taskUserSelect.nextTask.length > 0) {
        if (this.selectUser.length > 1) {
          // 修复15226 【流程提交】流程节点配置“分支节点必须选人”后，流程提交时的提示信息不对
          const message = this.selectUser.reduce((pre, tim, i) => {
            if (this.isMustUser(i)) {
              if (tim.users.length === 0) {
                const data = this.taskUserSelect.nextTask[i];
                pre.push(data ? data.currentActivityAttr.activityAlias : '当前');
              }
            }
            return pre;
          }, []);
          // 多个分支节点则未选择的分支节点必选时 提醒选人
          if (message.length > 0) {
            resMessage = `请选择【${message.join(',')}】节点处理人！`;
          }
          if (resMessage === '') {
            let isSelect = false;
            this.selectUser.forEach((tim) => {
              if (tim.users.length > 0) {
                isSelect = true;
              }
            });
            if (isSelect === false) {
              resMessage = '请选择处理人！';
            }
          }
        } else {
          let isSelect = false;
          this.selectUser.forEach((tim) => {
            if (tim.users.length > 0) {
              isSelect = true;
            }
          });
          if (isSelect === false) {
            resMessage = '请选择处理人！';
          }
        }
      }
      return resMessage;
    },

    // 判断是否选人
    noNeedSelectUser() {
      if (this.taskUserSelect.nextTask && this.taskUserSelect.nextTask.length > 0) {
        let count = 0;
        for (let i = 0; i < this.taskUserSelect.nextTask.length; i++) {
          const nextActorModel = this.taskUserSelect.nextTask[i];
          if (nextActorModel.activityType === 'end') {
            return true;
          }
          if (nextActorModel.activityType === 'sub-process' || nextActorModel.activityType === 'foreach') {
            if (nextActorModel.currentActivityAttr.isMustUser === 'yes') {
              return false;
            }
            count = count + 1;
          }
        }
        if (this.taskUserSelect.nextTask.length > 0 && count === this.taskUserSelect.nextTask.length) {
          return true;
        }
        // 勾选了意见-允许提交不弹框，则优先级最高，不用再选择处理人
        // if (this.taskUserSelect.currentActivityAttr.canHideDialog === 'yes') {
        //   return true;
        // }
        return false;
      }
      return true;
    },
    // 判断是否填写意见
    isOpinion() {
      const bpmCommonSelect = this.getButtonData();
      let isOpinion = true;
      // 如果是自定义选人则不显示输入意见框
      if (this.submitFuncName === 'BpmStepuserdefinedSubmit') {
        return isOpinion;
      }
      if (bpmCommonSelect.buttonData.event === 'dosubmit') {
        if (this.taskUserSelect.currentActivityAttr.ideaType === 'must') {
          if (this.$refs[this.flowOpinionRefName] && !this.$refs[this.flowOpinionRefName].getInputText()) {
            isOpinion = false;
          }
        } // 判断退回是否需要填写意见
      } else if (
        bpmCommonSelect.buttonData.event === 'doretreattodraft' ||
        bpmCommonSelect.buttonData.event === 'doretreattoprev' ||
        bpmCommonSelect.buttonData.event === 'doretreattowant' ||
        bpmCommonSelect.buttonData.event === 'doretreattoactivity'
      ) {
        if (this.taskUserSelect.currentActivityAttr.isNeedIdea === 'yes') {
          // 意见必须填写
          if (this.$refs[this.flowOpinionRefName] && !this.$refs[this.flowOpinionRefName].getInputText()) {
            isOpinion = false;
          }
        }
      } else if (bpmCommonSelect.buttonData.event === 'dosupersede') {
        // 转办意见必填
        if (this.taskUserSelect.currentActivityAttr.isNeedZbIdea === 'yes') {
          if (this.$refs[this.flowOpinionRefName] && !this.$refs[this.flowOpinionRefName].getInputText()) {
            isOpinion = false;
          }
        }
      }
      return isOpinion;
    },
    // 打开流程委托
    openWorkHandUser(result) {
      if (result && result.users.length > 0) {
        let selectWorkHand = [];
        this.processKey = this.taskUserSelect.processKey;
        result.users.forEach((tim) => {
          selectWorkHand = selectWorkHand.concat(tim.selectedUsers);
        });
        this.selectWorkHand = selectWorkHand;
        this.$refs.selectWorkHandUser.loadWorkHandUserData(this.processKey, this.selectWorkHand);
      }
    },
    // 流程委托选人点击确定
    getSelectWorkHandUserList(list) {
      const result = this.getResultUserData(this.compelManner);
      const bpmCommonSelect = this.getButtonData();
      if (result && result.users.length > 0) {
        result.users.forEach((tim) => {
          tim.workhandUsers = list;
        });
      }
      if (this.visible) {
        this.$emit('bpmSubmit', { users: result, buttonData: bpmCommonSelect.buttonData });
        this.selectVisible = false;
      } else {
        if (this.submitFuncName) {
          this[this.submitFuncName](this.bpmInstanceObject, {
            users: JSON.stringify(result),
            buttonData: bpmCommonSelect.buttonData
          });
        } else {
          this.$emit('afterBpmButtons', { users: result, buttonData: bpmCommonSelect.buttonData });
          this.$emit('bpmSubmit', { users: result, buttonData: bpmCommonSelect.buttonData });
          this.selectVisible = false;
        }
      }
    },
    // 流程委托选人点击取消
    closeSelectWorkHandUserList() {
      this.spinningButton = false;
    },
    // 判断是否存在工作移交
    checkWorkHandUser() {
      const bpmCommonSelect = this.getButtonData();
      if (
        bpmCommonSelect.buttonData.event === 'doretreattodraft' || // 退回拟稿人
        bpmCommonSelect.buttonData.event === 'doretreattoprev' || // 退回上一步
        bpmCommonSelect.buttonData.event === 'doretreattowant' || // 任意退回
        bpmCommonSelect.buttonData.event === 'doretreattoactivity' || // 退回到taskName节点
        bpmCommonSelect.buttonData.event === 'dowithdraw' || // 拿回
        bpmCommonSelect.buttonData.event === 'dotransmit' || // 发送阅知
        bpmCommonSelect.buttonData.event === 'dotaskreader' || // 增加读者
        bpmCommonSelect.buttonData.event === 'dowithdrawassignee' || // 减签
        bpmCommonSelect.buttonData.event === 'dowithdrawpart' // 拿回部分待办
      ) {
        return false;
      }
      if (this.taskUserSelect && this.taskUserSelect.nextTask) {
        for (let i = 0; i < this.taskUserSelect.nextTask.length; i++) {
          const jsonData = this.taskUserSelect.nextTask[i];
          if (jsonData.currentActivityAttr.isWorkHandUser === 'yes') {
            return true;
          }
        }
      } else {
        return false;
      }
      return false;
    },
    // 获取按钮数据
    getButtonData() {
      if (this.visible) {
        return { buttonData: this.buttonData, submitFuncName: '' };
      }
      return this.bpmInstanceObject.bpmCommonSelect;
    },
    // 加工点击确定返回数据
    getResultUserData(compelManner) {
      const idea = this.$refs[this.flowOpinionRefName] ? this.$refs[this.flowOpinionRefName].getText() : '';
      const bpmCommonSelect = this.getButtonData();
      const resultData = {
        idea,
        compelManner,
        outcome: bpmCommonSelect.buttonData.name
      };
      const users = [];
      if (this.taskUserSelect && this.taskUserSelect.nextTask && this.taskUserSelect.nextTask.length > 0) {
        const { outcome } = this.taskUserSelect.currentActivityAttr;
        this.taskUserSelect.nextTask.forEach((tim, index) => {
          const select = this.selectUser.filter((us) => us.selectFlowTab === index);
          if (select && select.length > 0) {
            const selectedUsers = [];
            select[0].users.forEach((user) => {
              selectedUsers.push({
                userId: user.id,
                userName: user.title,
                deptId: user.attributes.deptId,
                deptName: user.attributes.deptName
              });
            });
            const user = {
              outcome,
              targetActivityName: tim.currentActivityAttr.activityName,
              selectedUsers,
              workhandUsers: []
            };
            users.push(user);
          }
        });
      }
      resultData.users = users;
      return resultData;
    },
    // 清空数据
    empty() {
      this.selectUser = [];
      this.userBoxList = [];
      this.spinningButton = false;
      this.selectFlowTab = 0;
    },
    // 完全关闭回掉
    afterClose() {
      this.spinningButton = false;
    },
    changeSelectUser(e) {
      this.selectUser = e;
      // 去掉重复的选择用户
      // this.repeatSelectUser();
      const treeRef = this.treeRefName + this.selectFlowTab + this.selectTag;
      if (this.$refs[treeRef] && this.$refs[treeRef][0]) {
        this.$refs[treeRef][0].changeSelectUser(e);
      }
    },
    onChange(data) {
      const selectUserBoxRef = this.selectUserBoxRefName + this.selectFlowTab;
      if (this.$refs[selectUserBoxRef] && this.$refs[selectUserBoxRef].length >= 0) {
        this.$refs[selectUserBoxRef][0].getUserData(data);
      }
    },

    // 设置传入的默认选中
    setDefaultSelectUsers(defaultSelectUsers) {
      if (
        defaultSelectUsers != null &&
        defaultSelectUsers.users != null &&
        defaultSelectUsers.users.users != null &&
        defaultSelectUsers.users.users.length > 0 &&
        this.taskUserSelect != null
      ) {
        const selectUser = [];
        this.taskUserSelect.nextTask.forEach((tim, index) => {
          defaultSelectUsers.users.users.forEach((user) => {
            if (user.targetActivityName === tim.currentActivityAttr.activityName) {
              if (user.selectedUsers && user.selectedUsers.length > 0) {
                const usersList = [];
                user.selectedUsers.forEach((arr) => {
                  usersList.push({
                    key: arr.userId + arr.deptId,
                    title: arr.userName,
                    id: arr.userId,
                    name: arr.userName,
                    deptId: arr.deptId,
                    deptName: arr.deptName,
                    attributes: {
                      deptId: arr.deptId,
                      deptName: arr.deptName,
                      nodeType: 'user'
                    }
                  });
                });
                if (usersList && usersList.length > 0) {
                  selectUser.push({
                    selectFlowTab: index,
                    users: usersList
                  });
                }
              }
            }
          });
        });
        if (selectUser && selectUser.length > 0) {
          if (this.selectUser.length > 0) {
            if (selectUser.length === 1 && selectUser[0].users.length > 0) {
              this.selectUser = selectUser;
            } else {
              selectUser.forEach((newusers, i) => {
                if (i <= this.selectUser.length) {
                  newusers.users.forEach((newuser) => {
                    let isAdd = true;
                    this.selectUser[i].users.forEach((user) => {
                      if ((newuser.id = user.id)) {
                        isAdd = false;
                      }
                    });
                    if (isAdd) {
                      this.selectUser[i].users.push(newuser);
                    }
                  });
                } else {
                  const select = this.selectUser.filter((us) => us.selectFlowTab === newusers.selectFlowTab);
                  if (select.length <= 0) {
                    this.selectUser.push(newusers);
                  }
                }
              });
            }
          } else {
            this.selectUser = selectUser;
          }
          // 设置默认页签值
          this.selectTag = this.userBoxList[0].tabs[0].nodeType;
          setTimeout(() => {
            this.setValueToTreeAndBox();
          }, 600);
        }
      }
    },
    // 分别为左侧树和右侧列表赋值
    setValueToTreeAndBox() {
      const treeRef = this.treeRefName + this.selectFlowTab + this.selectTag;
      if (this.$refs[treeRef] && this.$refs[treeRef].length > 0) {
        this.$refs[treeRef][0].setDefaultSelectUser(this.selectUser);
      }
      const selectUserBoxRef = this.selectUserBoxRefName + this.selectFlowTab;
      if (this.$refs[selectUserBoxRef] && this.$refs[selectUserBoxRef].length > 0) {
        this.$refs[selectUserBoxRef][0].getUserData(this.selectUser);
      }
    },
    // 获取设置的配置选人
    getBpmStepPerson() {
      const { taskUserSelect } = this;
      if (taskUserSelect) {
        request({
          url: this.bpmStepPersonParam.url,
          data: {
            entryId: taskUserSelect.nextTask[0].currentActivityAttr.processInstanceId,
            activityName: taskUserSelect.nextTask[0].currentActivityAttr.activityName
          },
          method: this.bpmStepPersonParam.method
        }).then((res) => {
          if (res.success && res.data.length > 0) {
            if (this.taskUserSelect.nextTask.length > 0) {
              const usersList = [];
              res.data.forEach((user) => {
                usersList.push({
                  key: user.id,
                  title: user.name,
                  id: user.id,
                  name: user.name,
                  deptId: user.deptId,
                  deptName: user.deptName,
                  attributes: {
                    deptId: user.deptId,
                    deptName: user.deptName,
                    nodeType: 'user'
                  }
                });
              });
              if (this.selectUser.length > 0) {
                if (this.selectUser.length === 1 && this.selectUser[0].users.length > 0) {
                  this.selectUser = [{ selectFlowTab: 0, users: usersList }];
                } else {
                  usersList.forEach((newUser) => {
                    let isAdd = true;
                    this.selectUser[0].users.forEach((user) => {
                      if (user.id === newUser.id) {
                        isAdd = false;
                      }
                    });
                    if (isAdd) {
                      this.selectUser[0].users.push(newUser);
                    }
                  });
                }
              } else {
                this.selectUser = [{ selectFlowTab: 0, users: usersList }];
              }
              setTimeout(() => {
                this.setValueToTreeAndBox();
              }, 600);
            }
          }
        });
      }
    },
    /**
     * -----------------------自动选人-------------------------------------------
     */
    // 设置自动选人
    setAutoUser(userList, tabIndex) {
      if (userList && userList.length > 0) {
        userList.forEach((user) => {
          this.selectUser.forEach((tim) => {
            if (tim.selectFlowTab === tabIndex) {
              const select = tim.users.filter((item) => item.id === user.id);
              if (select.length === 0) {
                tim.users.push(user);
              }
            }
          });
        });
      }
    },
    // 自动选人
    autoSelectUser(_nextActorModel, tabIndex) {
      // 部门
      if (_nextActorModel.orgDeptUserList != null && _nextActorModel.orgDeptUserList.length && _nextActorModel.orgDeptUserList.length > 0) {
        const selectUser = setUserList(_nextActorModel.orgDeptUserList);
        this.setAutoUser(selectUser, tabIndex);
      }
      // 用户
      if (_nextActorModel.userList != null && _nextActorModel.userList.length && _nextActorModel.userList.length > 0) {
        const selectUser = setUserList(_nextActorModel.userList);
        this.setAutoUser(selectUser, tabIndex);
      }
      // 群组
      if (_nextActorModel.groupUserList != null && _nextActorModel.groupUserList.length && _nextActorModel.groupUserList.length > 0) {
        const selectUser = setUserList(_nextActorModel.groupUserList);
        this.setAutoUser(selectUser, tabIndex);
      }
      // 角色
      if (_nextActorModel.roleUserList != null && _nextActorModel.roleUserList.length && _nextActorModel.roleUserList.length > 0) {
        const selectUser = setUserList(_nextActorModel.roleUserList);
        this.setAutoUser(selectUser, tabIndex);
      }
      // 岗位
      if (
        _nextActorModel.positionUserList != null &&
        _nextActorModel.positionUserList.length &&
        _nextActorModel.positionUserList.length > 0
      ) {
        const selectUser = setUserList(_nextActorModel.positionUserList);
        this.setAutoUser(selectUser, tabIndex);
      }
    },
    // 单人处理自动选人
    autoSelectUserSingle(_nextActorModel, tabIndex) {
      // 部门
      if (_nextActorModel.orgDeptUserList != null && _nextActorModel.orgDeptUserList.length && _nextActorModel.orgDeptUserList.length > 0) {
        const selectUser = setUserList([_nextActorModel.orgDeptUserList[0]]);
        this.setAutoUser(selectUser, tabIndex);
        return;
      }
      // 用户
      if (_nextActorModel.userList != null && _nextActorModel.userList.length && _nextActorModel.userList.length > 0) {
        const selectUser = setUserList([_nextActorModel.userList[0]]);
        this.setAutoUser(selectUser, tabIndex);
        return;
      }
      // 群组
      if (_nextActorModel.groupUserList != null && _nextActorModel.groupUserList.length && _nextActorModel.groupUserList.length > 0) {
        const selectUser = setUserList([_nextActorModel.groupUserList[0]]);
        this.setAutoUser(selectUser, tabIndex);
        return;
      }
      // 角色
      if (_nextActorModel.roleUserList != null && _nextActorModel.roleUserList.length && _nextActorModel.roleUserList.length > 0) {
        const selectUser = setUserList([_nextActorModel.roleUserList[0]]);
        this.setAutoUser(selectUser, tabIndex);
        return;
      }
      // 岗位
      if (
        _nextActorModel.positionUserList != null &&
        _nextActorModel.positionUserList.length &&
        _nextActorModel.positionUserList.length > 0
      ) {
        const selectUser = setUserList([_nextActorModel.positionUserList[0]]);
        this.setAutoUser(selectUser, tabIndex);
        return;
      }
    },
    // 自动选人
    autoSelectToCheckUserList() {
      if (this.taskUserSelect.nextTask && this.taskUserSelect.nextTask.length > 0) {
        const bpmCommonSelect = this.getButtonData();
        const { event } = bpmCommonSelect.buttonData;
        this.taskUserSelect.nextTask.forEach((tim, index) => {
          if (this.isUserSelectTypeAuto(tim) || isAutoSelectUser(event)) {
            if (tim.currentActivityAttr?.dealType === '1') {
              // 单人处理
              this.autoSelectUserSingle(tim, index);
            } else {
              this.autoSelectUser(tim, index);
            }
          }
        });
      }
    },
    // 判断是否自动选中
    isUserSelectTypeAuto(_nextActorModel) {
      if (_nextActorModel != null && 'auto' === _nextActorModel.currentActivityAttr.userSelectType) {
        return true;
      }
      return false;
    },
    // 去掉重复的 selectFlowTab
    repeatSelectUser() {
      if (this.userBoxList.length !== this.selectUser.length) {
        this.selectUser.forEach((user, index) => {
          const { selectFlowTab } = user;
          const select = this.selectUser.filter((us) => us.selectFlowTab === selectFlowTab);
          if (select.length > 1) {
            this.selectUser.splice(index, 1);
          }
        });
      }
    }
  }
};
</script>
<style lang="less">
.main {
}
.main_modal {
  .head-tab {
    .ant-tabs-nav-wrap {
      padding: 0 12px;
      .ant-tabs-tab {
        margin-right: 8px;
        font-size: @font-size-lg;
        .head-tab {
          font-weight: 600;
        }
      }
    }
  }
  .user-tab {
    .ant-tabs-nav-wrap {
      padding: 0px 16px;
      .ant-tabs-tab {
        margin-right: 12px;
        .head-tab {
          font-weight: 600;
        }
      }
    }
  }
  .required {
    color: red;
  }
  .choose {
    display: flex;
    border-bottom: 1px solid @border-color-split;
    .left,
    .right {
      width: 50%;
      height: 100%;
      float: left;
    }
    .left {
      border-right: 1px solid @border-color-split;

      .ant-tabs-nav {
        // margin-bottom: 8px;
        padding: 8px 8px 0 8px;
        .ant-tabs-nav-wrap {
          padding: 0;
          .ant-tabs-tab {
            margin-right: 0;
            font-size: @font-size-base;
            padding: 4px 16px;
            .head-tab {
              font-weight: normal;
            }
          }
        }
      }
      .tree-box {
        height: 310px;
        padding: 8px 8px 0 8px;
        .search-box {
          margin-bottom: 4px;
          display: flex;
        }
        .ant-tree-checkbox {
          margin: 4px 4px 0 0;
        }
      }
      .ant-tree-title {
        .avic-icon {
          margin-right: 4px;
          font-size: 1.3em;
          // vertical-align: -0.225em;
        }
      }
    }
    .right {
      .container-box {
        .container-right-top {
          display: flex;
          align-items: center;
          padding: 8px;
          line-height: 23px;
          border-bottom: 1px solid @border-color-split;
          .total-delete-icon {
            margin-right: 8px;
            margin-left: auto;
            cursor: pointer;
            &:hover {
              color: red;
              fill: red;
            }
          }
        }
        .surely-table-body {
          height: 310px;
          .surely-table-cell {
            border: 0;
            .avic-icon {
              margin-right: 4px;
              font-size: 1.3em;
              vertical-align: -0.525em;
            }
            .checkclose {
              margin-right: 8px;
              margin-left: auto;
              color: @text-color-less;
              cursor: pointer;
              fill: @text-color-less;
              &:hover {
                color: red;
                fill: red;
              }
            }
            .surely-table-drag-handle {
              margin-left: 8px;
              color: @text-color-less;
              cursor: move;
              fill: @text-color-less;
            }
          }
          .checkclose {
            margin-right: 8px;
            margin-left: auto;
            color: @text-color-less;
            fill: @text-color-less;
          }
          .surely-table-drag-handle {
            margin-left: 8px;
            color: @text-color-less;
            fill: @text-color-less;
          }
        }
      }
    }
  }
  .select-count {
    // height: 100%;
    .ope-box {
      height: 100%;
    }
    .ant-popover-title {
      display: flex;
      flex-direction: row-reverse;
      padding: 4px;
    }
    .ant-popover-inner-content {
      min-height: 120px;
      padding: 4px;
      .popover-box-ul {
        margin-bottom: 0;
        padding: 0;
        height: 180px;
        overflow: auto;
        li {
          display: flex;
          align-items: center;
          justify-content: space-between;
          padding: 4px;
          width: 220px;
          &:hover {
            color: @primary-color;
            background: @primary-1;
          }
          .table-handle-button {
            color: @text-color-less;
            cursor: pointer;
            fill: @text-color-less;
            &:hover {
              color: red;
              fill: red;
            }
          }
        }
      }
    }
    .ant-input,
    .ant-input:focus,
    .ant-input-focused,
    .ant-input:hover {
      border: 0;
      box-shadow: none;
    }

    .ant-input-textarea-show-count::after {
      position: absolute;
      right: 4px;
      bottom: 4px;
      z-index: 2;
    }
    .tool-box {
      display: flex;
      align-items: center;
      padding: 4px 8px;
      font-size: @font-size-base;
      background: @table-header-bg;
      .right {
        margin-left: auto;
      }
      .idea-box {
        margin-right: 4px;
        font-weight: 600;
      }
      .ant-tag > .anticon + span,
      .ant-tag > span + .anticon {
        margin-left: 4px;
      }
    }
  }
  .ant-tabs-nav-operations {
    width: 92px;
  }
}
.flow-table-box {
  .user-icon {
    .avic-icon {
      font-size: 1.3em;
      margin-right: 4px;
      vertical-align: -0.525em;
    }
  }
}
.cell-txt {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
}
.cell-txt-dept {
  color: #86909c;
}
</style>
